package cn.hzking.gjmall.utils.helpers;

import android.content.Context;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;

import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration;

import cn.hzking.gjmall.utils.ScreenTool;

/**
 * Created by Administrator on 2018/2/2.
 */

public final class VHDivider {

    /**
     * 添加横向分割线(实线)
     * @param mContext
     * @param recyclerView
     * @param mColor
     * @param mSize
     * @param maginLeft
     * @param maginRight
     * @return
     */
    public static RecyclerView addHorizontalDivider(Context mContext,
                                                    RecyclerView recyclerView,
                                                    int mColor,
                                                    int mSize,
                                                    int maginLeft,
                                                    int maginRight){
        recyclerView.addItemDecoration(
                new HorizontalDividerItemDecoration.Builder(mContext)
                        .color(mColor)
                        .size(ScreenTool.dpTopx(mContext,mSize))
                        .margin(maginLeft, maginRight)
                        .build());
        return recyclerView;
    }


    /**
     * 添加竖向分割线(实线)
     * @param mContext
     * @param recyclerView
     * @param mColor
     * @param mSize
     * @param maginTop
     * @param maginButtom
     * @return
     */
    public static RecyclerView addVerticalDivider(Context mContext,
                                                    RecyclerView recyclerView,
                                                    int mColor,
                                                    int mSize,
                                                    int maginTop,
                                                    int maginButtom){
        recyclerView.addItemDecoration(
                new VerticalDividerItemDecoration.Builder(mContext)
                        .color(mColor)
                        .size(ScreenTool.dpTopx(mContext,mSize))
                        .margin(maginTop, maginButtom)
                        .build());
        return recyclerView;
    }

    /**
     *横向虚线分割线
     * @param mContext
     * @param recyclerView
     * @param mColor
     * @param mSize
     * @param maginLeft
     * @param maginRight
     * @return
     */
    public static RecyclerView addHorizontalDashDivider(Context mContext,
                                                        RecyclerView recyclerView,
                                                        int mColor,
                                                        int mSize,
                                                        int maginLeft,
                                                        int maginRight){
        Paint paint = new Paint();
        paint.setStrokeWidth(mSize);
        paint.setColor(mColor);
        paint.setAntiAlias(true);
        //第一个参数:25px实线,25px透明  第二个参数: 这时偏移为0，先绘制实线，再绘制透明 (如果是25,就先画虚线在话实线)
        paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0));
        recyclerView.addItemDecoration(
                new HorizontalDividerItemDecoration.Builder(mContext).paint(paint)
                        .margin(ScreenTool.dpTopx(mContext,maginLeft),ScreenTool.dpTopx(mContext,maginRight)).build());

        return recyclerView;
    }


    /**
     * 竖向虚线分割线
     * @param mContext
     * @param recyclerView
     * @param mColor
     * @param mSize
     * @param magigTop
     * @param maginButtom
     * @return
     */
    public static RecyclerView addVerticalDashDivider(Context mContext,
                                                        RecyclerView recyclerView,
                                                        int mColor,
                                                        int mSize,
                                                        int magigTop,
                                                        int maginButtom){
        Paint paint = new Paint();
        paint.setStrokeWidth(mSize);
        paint.setColor(mColor);
        paint.setAntiAlias(true);
        paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0));
        recyclerView.addItemDecoration(
                new HorizontalDividerItemDecoration.Builder(mContext).paint(paint)
                        .margin(ScreenTool.dpTopx(mContext,magigTop),ScreenTool.dpTopx(mContext,maginButtom)).build());

        return recyclerView;
    }


}
